import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import moment from 'moment';
const { Link } = router;

export default (self) => [
  {
    title: 'ID',
    name: 'id',
    // tableItem: {},
    // searchItem: {
    //   group: 'abc'
    // },
    formItem: {
      type: 'hidden',
    }
  },
  {
    title: '标题',
    name: 'title',
    searchItem: {group:'abc'},
    tableItem: {},
    formItem: {
      rules:[]
    },
  },
  {
    title: '跳转链接',
    name: 'url',
    tableItem: {},
    formItem: {
      rules:[]
    },
  },
  {
    title: '内容',
    name: 'content',
    formItem: {type: 'textarea'},
  }, {
    title: '状态',
    name: 'isPublish',
    dict: [{ code: 0, codeName: '未发布' }, { code: 1, codeName: '已发布' }],
    tableItem: { render: t=> t? '正常' : '停用'},
  }, {
    title: '创建时间',
    name: 'createTime',
    tableItem: {
      render: text =>
        moment.utc(text).format('YYYY-MM-DD HH:mm')
    },
  },
  { title: '文章头图',
    name: 'titlePic',
    formItem: {
      type: 'upload',
      action: '/articleManage/manage/uploadTitlePic',
      fileName: 'file',
      fileTypes: ['.png', '.jpg', '.gif'],
      listType: 'picture',
      normalize: value => {
        return [
          {
            uid: -1,
            thumbUrl: value
          }
        ];
      },
      max:1,
      multiple: false,
      // rules: [{required: true, message: '请上传图片'}]
    }
  },{
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => {
        let activeBtn;
        if (record.isPublish)
          activeBtn = <Button tooltip="取消" onClick={e =>self.handlePublish(record, 0)}><Icon type="StopOutlined" antd></Icon> </Button>;
        else
          activeBtn = <Button tooltip="发布" onClick={e =>self.handlePublish(record, 1)}><Icon type="CheckCircleOutlined" antd></Icon> </Button>;

        return <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit" />
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash" />
          </Button>
          {activeBtn}
        </DataTable.Oper>
      }
    }
  }
];
